var net = require('net');

var server = net.createServer();

var fs = require('fs');

server.on('connection', function(socket){

	console.log("客户端与服务器连接已建立");
	socket.setEncoding('utf8');
	// var readStream = fs.createReadStream('./server.js');
	// var readStream = fs.createReadStream('./xx.jpg');
	var readStream = fs.createReadStream('./yy.png');


	readStream.on('data', function(data){
		var flag = socket.write(data);
		console.log('\nwrite方法返回 ：' + flag);
		console.log("缓存队列当前缓存了%d字符", socket.bufferSize);
		console.log("已发送%d字节", socket.bytesWritten);
	});


	socket.on('data', function(data){
		console.log("已接收客户端发送的数据：" + data);
	});


	socket.on('drain', function(){
		console.log("TCP缓存区中数据已全部发送");
	});
});

server.listen(8433, 'localhost');